package com.guli.search.controller;

import com.guli.common.utils.R;
import com.guli.search.service.SearchService;
import com.guli.search.vo.SearchParam;
import com.guli.search.vo.SearchResult;
import com.guli.search.vo.SkuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author WZH
 * @title: SearchController
 * @projectName gulimall-java
 * @description:
 * @date 2022/1/7
 */
@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    @GetMapping(value = {"/","search.html"})
    public String gotoSearch( SearchParam searchParam,Model model){
        SearchResult result=searchService.gotoSearch(searchParam);
        model.addAttribute("result",result);
        return "search";
    }

    //批量添加
    @RequestMapping("/addAll")
    @ResponseBody
    public R addAll(@RequestBody List<SkuVo> collect) {
       return searchService.addAll(collect);
    }
}
